<!DOCTYPE html>
<html lang="zh-cn">
    <head>
		<meta charset="utf-8">
	    <meta http-equiv="X-UA-Compatible" content="IE=edge">
	    <meta name="viewport" content="width=device-width, initial-scale=1">
		<#include "/common/meta.ftl"/>
		<#include "/common/form.ftl"/>
		<script>
			$(function(){
				$("#form").validate({
					rules: {
						oldpwd: {required:true,maxlength:16},
						newpwd_: {required:true,maxlength:16},
						newpwd: {required:true,maxlength:16,equalTo:"#newpwd_"}
						
					},
					errorElement: "div",
					errorPlacement: function(error, element) {
						error.appendTo($(element).parent());
						$(element).parent().addClass("has-error");
						$(error).addClass("help-block alert-danger");
					},
					success: function(label) {
						$(label).parent().removeClass("has-error");
						$(label).remove();
					}
				})
			});

			function resetForm(){
		         $('#form').resetForm(); 		    
		    }
					    
		    function saveMypwd(){
	            $('#form').ajaxSubmit({
					beforeSubmit : function(a,f,o) {
						return $("#form").valid();
					},
					success : function(data) { // data 保存提交后返回的数据，一般为 json 数据
					    var json = JSON.parse(data); //由JSON字符串转换为JSON对象
					    var flag = json.success;
					    if (flag==true){
					        if(json.msg=='密码修改成功！'){
			                    var msg = new top.$.zui.Messager(json.msg, {
			                	    type : 'success',
			                	    fade : true,
			                	    //placement : 'bottom-right',
			                	    icon : 'ok-sign',
			                	    time : 3000,
			                	    scale : true
			                        });
			                        msg.show();
		                    }else{
			                    var msg = new top.$.zui.Messager(json.msg, {
			                	    type : 'warning',
			                	    fade : true,
			                	    //placement : 'bottom-right',
			                	    icon : 'remove-sign',
			                	    time : 3000,
			                	    scale : true
			                        });
			                        msg.show();
			                        $(document).ready(function(){  $("input[name=oldpwd]").focus();});
			                        $("input[name='oldpwd']").val("")		                        		                      
	                    }
		                }else{
			                    var msg = new top.$.zui.Messager(json.msg, {
			                	    type : 'danger',
			                	    fade : true,
			                	    //placement : 'bottom-right',
			                	    icon : 'remove-sign',
			                	    time : 3000,
			                	    scale : true
			                        });
			                        msg.show();
			                        $('#form').resetForm();
			                        $(document).ready(function(){  $("input[name=oldpwd]").focus();});    
		                }
		           }
				}); 
			}
		</script>
    </head>
<body style="padding:5px;">
<div class="panel panel-primary">
		<div class="panel-heading" style="">
			<strong>
			<i class="icon-user"></i>
			修改密码
			</strong>
		</div>
		<div class="panel-body" style="padding:5px;padding-top:15px;">
			<form id="form" class="form-horizontal" role="form" method='post' action="./myPassWdSave">
				<input type="hidden" name="userID" value="${userID}"/>
	    		<div class="form-group">
	      			<label class="col-md-1 col-md-offset-1 control-label required" >旧密码</label>
	          		<div class="col-md-3">
	             		<input type='text' name='oldpwd' id='oldpwd' value='' class='form-control' placeholder=''/>
	          		</div>
	    		</div>
	    		<div class="form-group">
	      			<label class="col-md-1 col-md-offset-1 control-label required" >新密码</label>
	          		<div class="col-md-3">
	             		<input type='password' name='newpwd_' id='newpwd_' value='' class='form-control' placeholder=''/>
	          		</div>
	    		</div>
	    		<div class="form-group">
	      			<label class="col-md-1 col-md-offset-1 control-label required"  >确认密码</label>
	          		<div class="col-md-3">
	             	    <input type='password' name='newpwd' id='newpwd' value='' class='form-control' placeholder=''/>
	          		</div>
	    		</div>
	    		<div class="form-group"  >
			         <div class="col-md-offset-2 col-md-10" >
		                 <button class="btn btn-primary" onclick="saveMypwd()" type="button"><i class="icon icon-save"></i> 保存</button>&nbsp;&nbsp;&nbsp;
		                 <button class="btn " onclick="resetForm()" type="button"><i class="icon icon-undo"></i> 重置</button>    
			         </div>  
		        </div>
	    	    </form>
	  	</div>
     </div>
</body>
</html>